<template>
  <div class="about">
    <h1>关于我们</h1>
    <p>这是WebApp1的关于页面</p>
    
    <div class="error-boundary-demo">
      <h2>错误边界组件演示</h2>
      <p>下面的组件被错误边界包裹，当发生错误时会显示友好的错误页面并自动上报到 Sentry。</p>
      
      <!-- 使用错误边界包裹可能出错的组件 -->
      <ErrorBoundary 
        :on-error="handleError"
        @error="onComponentError"
        @retry="onRetry"
        error-title="组件发生错误"
        error-message="很抱歉，此组件遇到了问题。错误已自动上报，我们会尽快修复。"
      >
        <BuggyComponent />
      </ErrorBoundary>
      
      <!-- 正常组件示例 -->
      <div class="normal-component">
        <h3>正常工作的组件</h3>
        <p>这个组件工作正常，不会触发错误边界。</p>
        <button @click="normalAction" class="normal-btn">正常操作</button>
      </div>
    </div>
    
    <router-link to="/" class="nav-link">返回首页</router-link>
  </div>
</template>

<script setup lang="ts">
import ErrorBoundary from '../components/ErrorBoundary.vue'
import BuggyComponent from '../components/BuggyComponent.vue'

// 处理错误边界捕获的错误
const handleError = (error: Error, errorInfo: any) => {
  console.log('About page received error:', error)
  console.log('Error info:', errorInfo)
  
  // 可以在这里添加额外的错误处理逻辑
  // 比如发送到其他监控服务、记录用户行为等
}

// 组件错误事件处理
const onComponentError = (error: Error, errorInfo: any) => {
  console.log('Component error event triggered:', error, errorInfo)
}

// 重试事件处理
const onRetry = () => {
  console.log('User clicked retry button')
  // 可以在这里添加重试相关的逻辑
}

// 正常操作示例
const normalAction = () => {
  alert('正常操作执行成功！')
}

</script>

<style scoped>
.about {
  text-align: center;
  padding: 2rem;
  max-width: 800px;
  margin: 0 auto;
}

.error-boundary-demo {
  margin: 2rem 0;
  text-align: left;
}

.error-boundary-demo h2 {
  color: #2c3e50;
  margin-bottom: 1rem;
}

.error-boundary-demo p {
  color: #7f8c8d;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.normal-component {
  margin-top: 2rem;
  padding: 20px;
  border: 2px solid #27ae60;
  border-radius: 8px;
  background-color: #f8fff8;
}

.normal-component h3 {
  color: #27ae60;
  margin-bottom: 10px;
}

.normal-btn {
  padding: 8px 16px;
  background-color: #27ae60;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  margin-top: 10px;
  transition: background-color 0.2s;
}

.normal-btn:hover {
  background-color: #219a52;
}

.nav-link {
  display: inline-block;
  margin-top: 2rem;
  padding: 0.5rem 1rem;
  background-color: #42b883;
  color: white;
  text-decoration: none;
  border-radius: 4px;
}

.nav-link:hover {
  background-color: #369870;
}
</style>